package com.zyg.search.config;

import lombok.Data;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ----------------------------------------------
 * 作者: LMY
 * 功能: XX
 * 创建时间: 2021-11-02 22:01
 * ----------------------------------------------
 **/
@Data
@Configuration           //设置为配置类
@ConfigurationProperties(prefix = "elasticsearch")  //读取yaml文件中elasticsearch为前缀的值
public class ElasticsearchConfig {

    private String host;
    private int port;

    @Bean
    public RestHighLevelClient highLevelClient(){
        RestClientBuilder builder = RestClient.builder(new HttpHost(host,port));
        return new RestHighLevelClient(builder);
    }

}
